<template>
  <div class="page">
    <headerbar
      >{{ pageTitle }}
      <span
        v-if="tuihuan"
        class="head-btn-text flex"
        slot="btn"
        @click="goDtl()"
      >
        <span class="title">{{ userDtlInfo }}%</span>
        <span class="tip">我的答题率</span>
      </span>
    </headerbar>
    <section class="">
      <ul class="tab" v-if="!fromSuperMarket">
        <li @click="findGroupTopic()" :class="{ active: tabIndex == 0 }">
          <span>学习问答</span>
        </li>
        <li @click="noteWeek()" :class="{ active: tabIndex == 1 }">
          <span>一周一记</span>
        </li>
      </ul>
    </section>

    <section v-if="tabIndex == 1">
      <fetchData
        class="project-tip"
        :loading="hasNoteWeekLoading"
        :data="hasNoteWeek"
      ></fetchData>
      <div
        class="project-tip"
        v-if="hasNoteWeek && oneRecordTipData"
        v-html="oneRecordTipData.hint"
      ></div>
      <section class="block" v-if="hasNoteWeek" id="onAnswer">
        <div class="list-wenda">
          <div @click="" class="item pdb-1">
            <div class="icon">
              <span class="icon-text">记</span>
            </div>
            <div class="title-wrap">
              <div class="title">
                <span class="bold">本周内容</span>
                <span class="color-tip tip"
                  >（{{ noteWeekData.startTime }}-{{
                    noteWeekData.endTime
                  }}）</span
                >
              </div>
            </div>
          </div>
          <div class="line mgh-2"></div>
        </div>

        <div class="learn-wrap">
          <div
            class="learn-cont"
            v-if="hasNoteWeek"
            v-html="noteWeekData.content"
          ></div>
        </div>
      </section>
      <div
        class="text-center no-data"
        v-if="!hasNoteWeekLoading && !hasNoteWeek"
        style="margin-top: 55px"
      >
        <img src="../../../../static/images/no_data.png" alt="" />
        <p>无一周一记内容</p>
      </div>
      <!--   学习问答获奖名单     -->
      <section class="block" v-if="latestLottery">
        <div style="height: 20px"></div>
        <div class="project-tip" v-html="latestLottery.remarks"></div>
        <div class="myProject-img">
          <img
            :src="showImg(latestLottery.resultPic, true)"
            @click="showImagePreview(latestLottery.resultPic)"
            alt=""
          />
        </div>
      </section>
      <div style="height: 50px"></div>
    </section>

    <!--每日一答-->
    <section v-if="tabIndex == 0">
      <fetchData
        class="project-tip"
        :loading="isLoading"
        :data="tipData"
      ></fetchData>
      <div class="project-tip" v-if="hasAnswer" v-html="tipData.hint"></div>
      <section class="block" id="noteWeek">
        <div class="exam-wrap" v-if="hasAnswer">
          <fetchData
            class="project-tip"
            :loading="swipeDataLoading"
            :data="swipeData"
          ></fetchData>
          <div
            class="exam-item"
            v-for="(data, index) in swipeData"
            :key="data.id"
          >
            <h2
              class="organization-lists-title"
              v-if="findGroup.topicFlag === '1'"
            >
              <b>学习内容：</b>{{ data.learnTxt }}
              <!--<h2 class="organization-lists-title"><b>学习内容：</b>{{data.learnTxt}}-->
              <div v-if="data.fileId && data.fileId !== ''" class="content-img">
                <img
                  :src="tools.getImgUrl(data.fileId)"
                  @click="showImagePreview(data.fileId)"
                />
              </div>
            </h2>
            <ul>
              <li v-if="data.topicType === '1'" class="text-wrap">
                <div class="index">
                  <span class="icon-text">{{ index + 1 }}</span>
                </div>
                <div class="cont-wrap">
                  <h2 class="subject-title">【单选】{{ data.title }}</h2>
                  <p class="right-answer" v-if="findGroup.subResult === '1'">
                    正确答案：{{ data.rightAnswer }}
                  </p>
                  <div class="types-lists answer-notice-lists">
                    <div
                      v-for="(examAnswerVoList1, index_) in data.ext"
                      :key="examAnswerVoList1.index"
                    >
                      <div class="mui-input-row mui-radio mui-left flex-center">
                        <label class="answer-value"
                          >{{ examAnswerVoList1.title }}
                          <input
                            v-if="findGroup.subResult === '0'"
                            @click="
                              radioSelectItem(index, examAnswerVoList1.index)
                            "
                            :name="data.id"
                            value="type1"
                            type="radio"
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '1'
                            "
                            :name="data.id"
                            value="type3"
                            type="radio"
                            :checked="true"
                            disabled
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '0'
                            "
                            :name="data.id"
                            value="type3"
                            type="radio"
                            :checked="false"
                            disabled
                          />
                        </label>
                      </div>
                    </div>
                  </div>
                </div>
              </li>
              <li v-if="data.topicType === '2'" class="text-wrap">
                <div class="index">
                  <span class="icon-text">{{ index + 1 }}</span>
                </div>
                <div class="cont-wrap">
                  <h2 class="subject-title">【多选】{{ data.title }}</h2>
                  <p class="right-answer" v-if="findGroup.subResult === '1'">
                    正确答案：{{ data.rightAnswer }}
                  </p>
                  <div class="types-lists answer-notice-lists">
                    <div
                      v-for="(examAnswerVoList1, index_) in data.ext"
                      :key="examAnswerVoList1.index"
                    >
                      <div
                        class="mui-input-row mui-checkbox mui-left flex-center"
                      >
                        <label class="answer-value"
                          >{{ examAnswerVoList1.title }}

                          <input
                            v-if="findGroup.subResult === '0'"
                            @click="
                              checkboxSelectItem(index, examAnswerVoList1.index)
                            "
                            :name="data.id"
                            value="type2"
                            type="checkbox"
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '1'
                            "
                            :name="data.id"
                            value="type3"
                            type="checkbox"
                            :checked="true"
                            disabled
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '0'
                            "
                            :name="data.id"
                            value="type3"
                            type="checkbox"
                            :checked="false"
                            disabled
                          />
                        </label>
                      </div>
                    </div>
                  </div>
                </div>
              </li>
              <li v-if="data.topicType === '4'" class="text-wrap">
                <div class="index">
                  <span class="icon-text">{{ index + 1 }}</span>
                </div>
                <div class="cont-wrap">
                  <h2 class="subject-title">
                    【填空】
                    <input
                      type="text"
                      @blur="inputParentBlur"
                      class="input-hidden"
                      v-model="data._enterText"
                      @input="onInputParent($event, data)"
                      :id="'inputParent' + data.id"
                      autocomplete="off"
                    />
                    <template
                      v-for="(item, index) in writeTitle(data.title, data)"
                    >
                      <template v-if="index > 0"
                        ><span
                          :class="getWriteInputClass(data, index)"
                          :key="index"
                          class="write-block"
                          ><input
                            :key="'input' + data.id + index + key"
                            @click.stop="selectInput(data)"
                            type="text"
                            :id="'input' + data.id + index"
                            readonly
                            :value="getEnterVal(data, index - 1)"
                            maxlength="1" /></span
                      ></template>
                      <template>{{ item }}</template>
                    </template>
                  </h2>

                  <p class="right-answer" v-if="findGroup.subResult === '1'">
                    正确答案：{{ data.rightAnswer }}
                  </p>
                  <p class="pdv-2"></p>
                </div>
              </li>
              <div class="">
                <div
                  class="organization-lists-title"
                  v-if="data.originFlag == '4'"
                >
                  <b>出题者：</b><li class="text-right" v-html="data.originOrgName+'&#12288;'+data.originName"></li>
<!--                  {{ data.originOrgName }} <i class="pdh-2"></i>-->
<!--                  {{ data.originName }}-->
                </div>
              </div>
              <li v-if="data.topicType === '3'" class="text-wrap">
                <div class="index">
                  <span class="icon-text">{{ index + 1 }}</span>
                </div>
                <div class="cont-wrap">
                  <h2 class="subject-title">【判断题】{{ data.title }}</h2>
                  <p class="right-answer" v-if="findGroup.subResult === '1'">
                    正确答案：{{ data.rightAnswer }}
                  </p>
                  <div class="types-lists answer-notice-lists">
                    <div
                      v-for="(examAnswerVoList1, index_) in data.ext"
                      :key="examAnswerVoList1.index"
                    >
                      <div class="mui-input-row mui-radio mui-left flex-center">
                        <label class="answer-value"
                          >{{ examAnswerVoList1.title }}
                          <input
                            v-if="findGroup.subResult === '0'"
                            @click="
                              radioSelectItem(index, examAnswerVoList1.index)
                            "
                            :name="data.id"
                            value="type3"
                            type="radio"
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '1'
                            "
                            :name="data.id"
                            value="type3"
                            type="radio"
                            :checked="true"
                            disabled
                          />
                          <input
                            v-if="
                              findGroup.subResult === '1' &&
                              examAnswerVoList1.choose === '0'
                            "
                            :name="data.id"
                            value="type3"
                            type="radio"
                            :checked="false"
                            disabled
                          />
                        </label>
                      </div>
                    </div>
                  </div>
                </div>
              </li>
              <div
                class="organization-lists-title"
                v-if="data.originFlag == '2'"
              >
                <b class="text-left">出题者：</b><li class="text-right" v-html="data.originOrgName+'&#12288;'+data.originName"></li>
              </div>
            </ul>
          </div>
        </div>

        <div
          class="text-center no-data"
          v-if="!swipeDataLoading && !hasAnswer"
          style="margin-top: 55px"
        >
          <img src="../../../../static/images/no_data.png" alt="" />
          <p>今日无问答</p>
        </div>
      </section>
      <p class="pdv-2" style="clear: both"></p>
      <div
        class="default-block-btn mgh-6"
        v-preventReClick="1000"
        @click="submit($event)"
        v-if="alreadAnswer"
      >
        提交
      </div>
      <p class="pdv-2"></p>
    </section>

<!--    <div class="problem-setting-btn" @click="go()" v-if="!fromSuperMarket">-->
<!--          <div class="text">我要出题</div>-->
<!--    </div>-->
    <dragComp @goNext="go" :text="text"/>
  </div>
</template>

<script>
import api from "@/common/config/api";
import tools from "@/utils/tools";
import _ from "lodash";
import loginService from "@/service/loginService";
import moment from "moment";
import StorageKeys from "@/common/const/StorageKeys";
let isDebbug = false;
let isSubmiting = false; // 正在提交
export default {
  name: "oneAnswerEveryday",
  data() {
    return {
      orderId:'',
      latestLottery: {}, // 每日一答获奖名单
      isLoading: true,
      swipeDataLoading: true,
      hasNoteWeekLoading: true,
      fn: tools,
      key: "",
      pageTitle: "筑学习",
      tabIndex: 0,
      noteWeekData: {},
      hasNoteWeek: false,
      isInputing: false,
      hasAnswer: false,
      alreadAnswer: false,
      fromSuperMarket: false, // 红云超市
      answerScoreData: {}, // 积分兑换数据
      swipeData: [],
      groupTopic: {},
      findGroup: {},
      tipData: {},
      oneRecordTipData: {},
      userDtlInfo: 0.0,
      showButton: false,
      tuihuan: false,
      toast: null,
      getKey:'1', //判断是否走新页面 1 走老页面 0 新页面
      text:'我要出题',
    };
  },
  created() {
    if (this.$route.query.fromSuperMarket === true) {
      // this.getDictValue();//判断是否调用新接口
      this.orderId = this.$route.query.orderId
      this.isLoading = false;
      this.tuihuan = false;
      this.pageTitle = "积分兑换补答题";
      this.fromSuperMarket = this.$route.query.fromSuperMarket;
      this.answerScoreData = this.$store.state.answerScoreData;
      console.log(this.$route.query.fromSuperMarket);
      console.log(this.answerScoreData);
      this.hasAnswer = true;
      this.swipeData = this.answerScoreData.topicList;
      this.swipeData.forEach((v) => {
        if (typeof v.ext === 'string') v.ext = JSON.parse(v.ext);
      });
      this.findGroup = this.answerScoreData;
      this.alreadAnswer = true;
      this.onData();
      return true;
    }
    this.findGroupTopic(); // 获取今日答题
    this.findHints(); // 题目提示
    this.findOneRecordHints(); // 一周一记提示
    this.userDtlInfos(); //  查询用户答题率信息
    this.findUserQuestion(); // 查询是否已出题

    //测试代码
    // let data = {"groupTime":"2020-05-23","id":"88DAF4AA8C424E17A3477B730519C5F5","maxExamNum":3,"subResult":"0","subResultId":"","title":"2020-05-23一问一答","topicFlag":"1","topicList":[{"ext":"[{\"title\":\"范围分为非二哥哥如果\",\"right\":\"0\",\"index\":\"1\"},{\"title\":\"抚慰抚慰二个人各\",\"right\":\"0\",\"index\":\"3\"},{\"title\":\"违法让人个人谈话\",\"right\":\"1\",\"index\":\"4\"},{\"title\":\"违法个人个人威风\",\"right\":\"0\",\"index\":\"5\"}]","id":"0754E544AB38402A9630F7CF8914D891","learnTxt":"学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容学习内容1","originFlag":"1","originFlagName":"系统发布","originName":"","originOrgName":"","title":"单选问题测试1","topicType":"1","topicTypeName":"单选"},{"ext":"[{\"title\":\"二个人个人威风威风为发二个人各认购威风威风为发\",\"right\":\"1\",\"index\":\"1\"},{\"title\":\"二个人个人威风威风为发个人个人个人个\",\"right\":\"1\",\"index\":\"2\"},{\"title\":\"威风威风为发二个人各认购威风威风为发\",\"right\":\"1\",\"index\":\"3\"},{\"title\":\"二个人个人威风威风为发人个人个人个\",\"right\":\"1\",\"index\":\"4\"}]","id":"4A02F79A6D964163A90E5864EE3C2D9B","learnTxt":"多选题多选题学习内容多选题多选题学习内容多选题多选题学习内容多选题多选题学习内容","originFlag":"1","originFlagName":"系统发布","originName":"","originOrgName":"","title":"多选题测试","topicType":"2","topicTypeName":"多选"},{"ext":"[{\"title\":\"正确\",\"right\":\"1\",\"index\":\"1\"},{\"title\":\"错误\",\"right\":\"0\",\"index\":\"2\"}]","id":"FBD7AB35F6394FDCB52013CF809F495A","learnTxt":"威风威风为威风威风","originFlag":"1","originFlagName":"系统发布","originName":"","originOrgName":"","title":"判断题测试1","topicType":"3","topicTypeName":"判断"}]}
    // this.swipeData = data.topicList
    // this.swipeData.map((v, index) => {
    //   let rightAnswer = ''
    //   let extArr = JSON.parse(v.ext)
    //   extArr.map((w, index_) => {
    //     switch (index_) {
    //       case 0:
    //         w.title = 'A、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'A'
    //         }
    //         break
    //       case 1:
    //         w.title = 'B、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'B'
    //         }
    //         break
    //       case 2:
    //         w.title = 'C、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'C'
    //         }
    //         break
    //       case 3:
    //         w.title = 'D、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'D'
    //         }
    //         break
    //       case 4:
    //         w.title = 'E、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'E'
    //         }
    //         break
    //       case 5:
    //         w.title = 'F、' + w.title
    //         if (w.right === '1') {
    //           rightAnswer = rightAnswer + 'F'
    //         }
    //         break
    //     }
    //   })
    //   v.ext = extArr
    //   v.rightAnswer = rightAnswer
    //   v.fileId = 'd15292b782e24f29bcf7ada54e746652'
    // })
    // this.hasAnswer = true
  },
  methods: {
    /*页面初始化*/
    init() {},
    /*获取填空的值*/
    getEnterVal(item, index) {
      let itemIndex = this.swipeData.findIndex((v) => {
        return item.id === v.id;
      });
      console.log(this.swipeData[itemIndex]);
      return this.swipeData[itemIndex].enterText[index];
    },
    inputParentBlur() {
      this.isInputing = false;
    },
    selectInput(item) {
      event.target.blur();
      console.log("onselect _enterText", item._enterText, item.enterText);
      item._enterText = item.enterText.join("").trim();
      let el = document.getElementById("inputParent" + item.id);
      el.value = item._enterText;
      el.focus();
      this.isInputing = item.id;
      console.log("_enterText", item._enterText, item.enterText);
    },
    onInputParent(event, item) {
      let rightAnswer = item.rightAnswer.replace(/、/g, "");
      item._enterText = item._enterText.trim();
      item._enterText = item._enterText.substr(0, rightAnswer.length);
      let enterText = item._enterText.split("");
      this.key = Date.now();
      console.log("onInputParent _enterText", item._enterText, item.enterText);
      this.reWriteAnswer(item._enterText, item);
      item.enterText = enterText;
      //        let el = document.getElementById('inputParent' + item.id)
      //        let v = el.value
      //        el.value = ''
      //        el.focus()
      //        el.value = v
    },
    /*输入框*/
    onInput(event, item, index) {
      setTimeout(() => {
        console.log(event);
        // 删除
        if (event.target.value === "") {
          if (index <= 1) {
            return false;
          }
          let el = document.getElementById("input" + item.id + (index - 1));
          el.focus();
          return;
        }
        // 输入文字
        if (
          typeof event.target.value === "string" &&
          event.target.value.trim() !== ""
        ) {
          if (index >= item.enterText.length) {
            return false;
          }
          let el = document.getElementById("input" + item.id + (index + 1));
          el.focus();
        }
      }, 100);
    },
    /*是否填写填空题*/
    isInputWriteAnswer(answer) {
      if (!Array.isArray(answer) || answer.length < 1) {
        return false;
      }
      for (let i = 0; i < answer.length; i++) {
        let v = answer[i];
        if (v === undefined || v.trim() === "") {
          return false;
        }
      }
      return true;
    },
    /*正确答案的样式*/
    getWriteInputClass(data, index) {
      if (!data.rightAnswer) {
        return "";
      }
      // 是否答题状态
      let rightAnswer = data.rightAnswer.replace(/、/g, "");
      if (this.alreadAnswer && this.isInputing === data.id) {
        let answerLen = data.enterText.join("").trim().length;
        if (answerLen === 0 && index === answerLen + 1) {
          return "on-input";
        }
        if (
          (rightAnswer.length > answerLen && index === answerLen + 1) ||
          (rightAnswer.length === answerLen && answerLen === index)
        ) {
          return "on-input";
        }
      }
      if (this.alreadAnswer) {
        return false;
      }
      if (Array.isArray(data.enterText) && data.enterText.length < 1) {
        return "";
      }
      console.log("源答案：", rightAnswer);
      /*rightAnswer.splice(rightAnswer.findIndex(item => {
          console.log('findIndex：', item)
          return item === '、'
        }), 1)*/
      rightAnswer = rightAnswer.replace(/、/g, "").split("");
      console.log("对比源：", data.enterText, rightAnswer);
      console.log(
        "对比答案：",
        data.enterText[index - 1],
        rightAnswer[index - 1]
      );
      return data.enterText[index - 1] === rightAnswer[index - 1]
        ? "right"
        : "error";
    },
    /*获取填空答案*/
    getAnswerArr(answers, item) {
      let ret = [];
      let temp = [];
      let i = 0;
      let answerLenModel = item.title.match(/(\[@\])+/g);
      answerLenModel = answerLenModel.map((v) => {
        return v.replace(/\[@\]/g, "@");
      });
      for (; i < answers.length; i++) {
        var v = answers[i];
        if (v === undefined || v === "") {
          temp.push(" ");
        } else {
          temp.push(v);
        }
      }
      temp = temp.join("").split("&^");
      temp.forEach((v) => {
        if (v !== "") {
          ret.push(v);
        }
      });
      if (answerLenModel.length !== ret.length) {
        let str = ret[0];
        let lastIndex = 0;
        answerLenModel.map((v, index) => {
          ret[index] = str.substr(lastIndex, v.length);
          lastIndex += v.length;
        });
      }
      ret = ret.map((v, index) => {
        let modelLen = answerLenModel[index].replace(/\[@\]/g, "@").length;
        return v.substr(0, modelLen);
      });
      return ret;
    },
    /*重填答案*/
    reWriteAnswer(enterText, item) {
      enterText += "              ";
      let answerLenModel = item.title.match(/(\[@\])+/g);
      let lastLen = 0;
      item.ext = item.ext.map((v, index) => {
        let modelLen = answerLenModel[index].replace(/\[@\]/g, "@").length;
        if (enterText && enterText.length >= modelLen + lastLen) {
          v.enterText = enterText.substr(lastLen, modelLen);
          lastLen += modelLen;
        }
        return v;
      });
    },
    /*填空题标题*/
    writeTitle(title, item) {
      item.enterText = [];
      if (item.ext[0].enterText) {
        let allEnterText = [];
        let answerLenModel = title.match(/(\[@\])+/g);
        item.ext.forEach((v, index) => {
          /*if (allEnterText.length > 0) {
              allEnterText.push('、')
            }*/
          let modelLen = answerLenModel[index].replace(/\[@\]/g, "@").length;
          if (v.enterText && v.enterText.length > modelLen) {
            v.enterText = v.enterText.substr(0, modelLen);
          }
          allEnterText.push(v.enterText);/*  */
        });

        item.enterText = allEnterText.join("").split("");
      }
      return title.split("[@]");
    },
    /*积分兑换答题*/
    savePointUserExam(data, rightNumber) {
      let params = _.extend(data, {
        groupId: this.answerScoreData.id,
        pointExchangeId: this.answerScoreData.pointExchangeId,
      });
      let date = _.extend(data, {
        groupId: this.answerScoreData.id,
        orderId:this.orderId,
        pointExchangeId: this.answerScoreData.pointExchangeId,
      });

      console.log("params={}", params);
      // 防止接口返回太慢
      isSubmiting = true;
      if(true){//新超市
      // if(this.getKey === '0'){//正常调用
        this.fetchService.saveOrderApplyDt(date).then((res) => {
          isSubmiting = false;
          if (res.code !== 0) {
            return tools.tip(res.message || "系统繁忙，请稍候再试！");
          }
          if (rightNumber === this.swipeData.length) {
            tools.alert("恭喜您全部答对！", (...arg) => {
              this.$router.replace({name: 'mallForRecordList'})
              // this.tools.back();
            });
          } else if (rightNumber === 0) {
            tools.alert("很遗憾，一题未对！", (...arg) => {
              this.$router.replace({name: 'mallForRecordList'})
              // this.tools.back();
            });
          } else {
            let tip = "您答对了" + rightNumber + "题！";
            tools.alert(tip, (...arg) => {
              this.$router.replace({name: 'mallForRecordList'})
              // this.tools.back();
            });
          }
        });
      }else {
        this.fetchService.savePointUserExam(params).then((res) => {
            isSubmiting = false;
            if (res.code !== 0) {
              return tools.tip(res.message || "系统繁忙，请稍候再试！");
            }
            if (rightNumber === this.swipeData.length) {
              tools.alert("恭喜您全部答对！", (...arg) => {
                this.tools.back();
              });
            } else if (rightNumber === 0) {
              tools.alert("很遗憾，一题未对！", (...arg) => {
                this.tools.back();
              });
            } else {
              let tip = "您答对了" + rightNumber + "题！";
              tools.alert(tip, (...arg) => {
                this.tools.back();
              });
            }
          });
      }

      //老接口
      // this.fetchService.savePoinmemberGradetUserExam(params).then((res) => {
      //   isSubmiting = false;
      //   if (res.code !== 0) {
      //     return tools.tip(res.message || "系统繁忙，请稍候再试！");
      //   }
      //   if (rightNumber === this.swipeData.length) {
      //     tools.alert("恭喜您全部答对！", (...arg) => {
      //       this.tools.back();
      //     });
      //   } else if (rightNumber === 0) {
      //     tools.alert("很遗憾，一题未对！", (...arg) => {
      //       this.tools.back();
      //     });
      //   } else {
      //     let tip = "您答对了" + rightNumber + "题！";
      //     tools.alert(tip, (...arg) => {
      //       this.tools.back();
      //     });
      //   }
      // });
    },
    oneAnswer() {
      this.swipeDataLoading = true;
      let data = {
        loginId: this.tools.getUserInfo().id || "112029",
        groupId: this.groupTopic.id,
        // subResultId: 'C0EE14E568AD47D9B7E275EC30405726'
        subResultId: this.groupTopic.subResultId,
      };
      loginService.findGroup(data).then((res) => {
        this.swipeDataLoading = false;
        if (res.code !== 0) {
          return tools.tip(res.message || "系统繁忙，请稍候再试！");
        }
        console.log("this.findGroup", this.findGroup);
        this.findGroup = res.data;
        this.swipeData = res.data.topicList;
        this.onData();
      });
    },
    /*在数据获取到后执行，进行数据清洗*/
    onData() {
      // test
      isDebbug && (this.findGroup.subResult = "0");
      this.swipeData.map((v, index) => {
        let rightAnswer = "";
        let extArr = v.ext;
        /*2020年12月11日 发现答题的接口格式由字符串变为object，引起报错*/
        if (typeof v.ext === 'string') {
          extArr = JSON.parse(v.ext)
        }
        extArr.map((w, index_) => {
          w._title = w.title;
          switch (index_) {
            case 0:
              w.title = "A、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "A";
              }
              break;
            case 1:
              w.title = "B、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "B";
              }
              break;
            case 2:
              w.title = "C、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "C";
              }
              break;
            case 3:
              w.title = "D、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "D";
              }
              break;
            case 4:
              w.title = "E、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "E";
              }
              break;
            case 5:
              w.title = "F、" + w.title;
              if (w.right === "1") {
                rightAnswer = rightAnswer + "F";
              }
              break;
          }
        });
        v.ext = extArr;
        v.rightAnswer = rightAnswer;
        // 填空题
        if (v.topicType === "4") {
          let _rightAnswers = [];
          extArr.forEach((v) => {
            _rightAnswers.push(v._title);
          });
          v.rightAnswer = _rightAnswers.join("、");
        }
      });
    },
    findGroupTopic() {
      this.tabIndex = 0;
      let data = {
        // groupTime: '2019-12-29' // 测试用
      };
      // loginService.findGroupTopicFlagTest(data).then((res) => {
      loginService.findGroupTopicFlag(data).then((res) => {
        if (res.code !== 0) {
          this.hasAnswer = false;
          this.showToastTxtOnly(res.message || "系统繁忙，请稍候再试！");
          return;
        }
        this.hasAnswer = true;
        this.groupTopic = res.data;
        if (res.data.subResult === "0") {
          this.alreadAnswer = true;
        } else {
          this.alreadAnswer = false;
        }
        // test
        isDebbug && (this.alreadAnswer = true);
        this.oneAnswer();
      });
    },
    noteWeek() {
      this.noteWeekData = {}
      this.latestLottery = "";
      // this.noteWeekData = ''
      if (this.toast) {
        this.toast.hide();
      }
      let params = {
        loginId: this.tools.getUserInfo().id,
      };
      this.tabIndex = 1;
      let data = {
        loginId: "3750",
      };
      loginService.findWeekDiary(data).then((res) => {
        this.hasNoteWeekLoading = false
        if (res.code !== 0) {
          this.hasNoteWeek = false
          return
          // return tools.tip(res.message)
        }
        this.hasNoteWeek = true;
        this.noteWeekData = res.data;

        //一周一记查看登记
        loginService
          .weekDiaryView({
            weekDiaryId: res.data.id,
          })
          .then((viewRes) => {
            if (viewRes.code !== 0) {
              return;
            }
            console.log("记录成功");
          });
      });
      loginService.findLatestLotteryResult(params).then((res) => {
        if (res.code !== 0) {
          return;
          // return tools.tip(res.message)
        }
        if (res.data != null || "" != res.data) {
          this.latestLottery = res.data;
        }
      });
    },
    showImg(fileId) {
      let fileUrl = this.tools.getImgUrl(fileId);
      console.log("-------------fileUrl=", fileUrl);
      return fileUrl;
    },
    showImagePreview(item) {
      if (item.fileId.length < 1) {
        return false;
      }
      let fileUrl = this.tools.getImgUrl(item.fileId);
      item.url = fileUrl;
      let imgs = [fileUrl];
      this.$createImagePreview(
        {
          initialIndex: 0,
          imgs: imgs,
        },
        (h) => {
          return h(
            "div",
            {
              class: {
                "image-preview-custom-header": false,
              },
              slot: "header",
            },
            ""
          );
        }
      ).show();
    },
    go() {
      if (!this.showButton) {
        return tools.alert("今日已出题");
      }
      this.$router.push({ path: `/problemSetting` });
    },
    getTime(createTime) {
      return moment(createTime).format("MM月DD日");
    },
    radioSelectItem(rootIndex, id) {
      // if (!this.swipeData[rootIndex].result) {
      //   this.selectNum++
      // }
      this.swipeData[rootIndex].result = id;
      console.log("result=", this.swipeData[rootIndex].result);
    },
    checkboxSelectItem(rootIndex, id) {
      if (this.swipeData[rootIndex].checkboxResult) {
        let index = this.swipeData[rootIndex].checkboxResult.indexOf(id);
        if (index !== -1) {
          this.swipeData[rootIndex].checkboxResult.splice(index, 1);
          // if (this.swipeData[rootIndex].checkboxResult.length === 0) {
          //   this.selectNum--
          // }
        } else {
          this.swipeData[rootIndex].checkboxResult.push(id);
        }
      } else {
        this.swipeData[rootIndex].checkboxResult = [];
        this.swipeData[rootIndex].checkboxResult.push(id);
        // this.selectNum++
      }
      console.log("checkboxResult=", this.swipeData[rootIndex].checkboxResult);
    },
    submit(e) {
      if (e.target.disabled || isSubmiting) {
        return false;
      }
      // test
      isDebbug && console.log("swipeData", this.swipeData);
      let resutList = [];
      let resultTtpe = true;
      let rightNumber = 0;
      this.swipeData.map((v, index) => {
        if (v.topicType === "4") {
          // 填空题
          v.result = true;
          // 是否填空
          if (!this.isInputWriteAnswer(v.enterText)) {
            resultTtpe = false;
          }
        } else if (v.topicType === "1" || v.topicType === "3") {
          if (!v.result) {
            resultTtpe = false;
          }
        } else if (v.topicType === "2") {
          if (!v.checkboxResult || v.checkboxResult.length === 0) {
            resultTtpe = false;
          }
        }
        if (!resultTtpe) {
          resultTtpe = false;
        } else {
          let subResult = [];
          let obj = {};
          obj.topicId = v.id;
          obj.subRight = "0";
          let right = true;
          // let extArr = JSON.parse(v.ext)
          v.ext.map((w, index_) => {
            let subObj = {};
            subObj.choose = "0";
            // 根据题型判断是否选择了正确的答案
            if (v.topicType === "2") {
              // console.log("JSON.stringify(v.checkboxResult)={}", JSON.stringify(v.checkboxResult))
              // 如果是多选题，那么判断有一个正确答案没有包含在选择的答案数组中，则认为答错了
              if (
                w.right === "1" &&
                !(JSON.stringify(v.checkboxResult).indexOf(w.index) !== -1)
              ) {
                right = false;
              }
              // 如果是多选题，如果选择的答案中包含非正确答案，则认为答错了
              if (
                w.right === "0" &&
                JSON.stringify(v.checkboxResult).indexOf(w.index) !== -1
              ) {
                right = false;
              }
              // 封装返回结果中选择的答案
              console.log(
                "JSON.stringify(v.checkboxResult)={}",
                JSON.stringify(v.checkboxResult)
              );
              console.log("w.index={}", w.index);
              if (JSON.stringify(v.checkboxResult).indexOf(w.index) !== -1) {
                subObj.choose = "1";
                subObj.index = w.index;
              } else {
                subObj.choose = "0";
                subObj.index = w.index;
              }
            } else if (v.topicType !== "4") {
              // 非填空题
              // 如果是单选题或者判断题，只需判断选择的是否是正确答案即可，记录的是索引
              if (w.right === "1" && w.index === v.result) {
                obj.subRight = "1";
                rightNumber++;
              }
              // 封装返回结果中选择的答案
              if (w.index === v.result) {
                subObj.choose = "1";
                subObj.index = w.index;
              } else {
                subObj.choose = "0";
                subObj.index = w.index;
              }
            }
            // 判断填空题
            if (v.topicType === "4") {
              let answer = this.getAnswerArr(v.enterText, v);
              console.log("填空题", w.title.split("、")[1], v.enterText);
              console.log("答案", answer);
              subObj.choose = "1";
              subObj.index = w.index;
              subObj.title = w.title.split("、")[1];
              subObj.enterText = answer[index_];
              if (w.title.split("、")[1] !== answer[index_]) {
                // 只要有一个是错的，后面就是错的
                right = false;
              }
            }
            subResult.push(subObj);
          });
          // 多选题判断是否选对答案
          if (v.topicType === "2" && right) {
            obj.subRight = "1";
            rightNumber++;
          }
          // 填空题
          if (v.topicType === "4" && right) {
            obj.subRight = "1";
            rightNumber++;
          }
          obj.subResult = subResult;
          resutList.push(obj);
        }
      });
      if (!resultTtpe) {
        return tools.tip("请答完所有题目再提交");
      }
      // test
      if (isDebbug) {
        console.log("答对题目数：", rightNumber);
        console.log("提交数据：", resutList);
        return false;
      }
      console.log("resultList={}", resutList);
      let subTopics = JSON.stringify(resutList);
      let data = {
        loginId: this.tools.getUserInfo().id || "112029",
        groupId: this.groupTopic.id,
        subTopics: subTopics,
      };
      console.log("this.data={}", data);
      console.log("this.fromSuperMarket={}", this.fromSuperMarket);
      if (this.fromSuperMarket) {
        return this.savePointUserExam(data, rightNumber);
      }
      // 防止接口返回太慢
      isSubmiting = true;
      let timeout1 = setTimeout(() => {
        isSubmiting = false;
      }, 3000);
      // loginService.saveGroupSubResultTest(data).then((res) => {
      loginService.saveGroupSubResult(data).then((res) => {
        isSubmiting = false;
        if (res.code !== 0) {
          return tools.tip(res.message || "系统繁忙，请稍候再试！");
        }
        this.$localStorage.set(StorageKeys.ONE_ANSWER_RESULT, res.data);
        // tools.tip('已提交')
        if (rightNumber === this.swipeData.length) {
          tools.alert("恭喜您全部答对！", (...arg) => {});
        } else if (rightNumber === 0) {
          tools.alert("很遗憾，一题未对！", (...arg) => {});
        } else {
          let tip = "您答对了" + rightNumber + "题！";
          tools.alert(tip, (...arg) => {});
        }
        this.alreadAnswer = false;
        this.userDtlInfo = res.data.dtl;
        //原来的答题率请求方式
        // this.userDtlInfos()
        // 在提交答案后不再获取答题内容
        //  this.findGroupTopic()
        this.groupTopic.subResultId = res.data.subResultId;
        console.log("this.swipeData", this.swipeData);
        // this.findGroup.subResult
        // this.alreadAnswer = true
        this.oneAnswer();
      });
    },
    findHints() {
      this.isLoading = true;
      let data = {
        type: "1",
      };
      loginService.findHints(data).then((res) => {
        this.isLoading = false;
        if (res.code === 0) {
          this.tipData = res.data;
          if (this.$store.state.oneAnswerFrom) {
            if (res.data.bulletBoxHint && res.data.bulletBoxHint !== "") {
              // tools.alert(res.data.bulletBoxHint, (...arg) => {});//原来的弹出框
              this.$createAnswerEverydayDialog({
                $props: {
                  prop: res.data.bulletBoxHint
                },
                $events: {
                  onSubmit: (data, apppraiseValue) => {
                    this.saveTeacherAppraise(item, data, apppraiseValue)
                  }
                }
              }).show()
            }
            this.$store.state.oneAnswerFrom = false;
          }
        }
      });
    },
    findOneRecordHints() {
      let data = {
        type: "3",
      };
      loginService.findHints(data).then((res) => {
        if (res.code === 0) {
          this.oneRecordTipData = res.data;
        }
      });
    },
    findUserQuestion() {
      let data = {};
      loginService.findUserQuestion(data).then((res) => {
        if (res.code !== 0) {
          this.showButton = false;
          //            this.showToastTxtOnly(res.message)
        } else {
          this.showButton = true;
        }
      });
    },
    userDtlInfos() {
      loginService.userDtlInfo().then((res) => {
        if (res.code === 0) {
          this.tuihuan = true;
          this.userDtlInfo = res.data.dtl;
        } else {
          //            this.showToastTxtOnly(res.message)
        }
      });
    },
    goDtl() {
      // let url =
      //   "http://www.djhy.gov.cn:8680/party-center/exam/h5/calendar/index.do?access_token=" +
      //   tools.getToken();
      let url = 'http://222.85.156.70:8888/exam/monthCalendar.html?token=' + tools.getToken()
      if (window.android && window.android.openUrlAdapt) {
        window.android.openUrlAdapt(url);
      }
    },
    showImagePreview(fileId) {
      if (fileId.length < 1) {
        return false;
      }
      let fileUrl = this.tools.getImgUrl(fileId);
      let imgs = [fileUrl];
      this.$createImagePreview(
        {
          initialIndex: 0,
          imgs: imgs,
        },
        (h) => {
          return h(
            "div",
            {
              class: {
                "image-preview-custom-header": false,
              },
              slot: "header",
            },
            ""
          );
        }
      ).show();
    },
    showToastTxtOnly(text) {
      this.toast = this.$createToast({
        txt: text,
        type: "txt",
        time: 3000,
        onTimeout: () => {
          this.toast.hide();
        },
      });
      this.toast.show();
    },
    //请求字典值
    getDictValue() {
      let data = {
        catKey: "CAT_MALL_",
        treeKey: "IS_OPEN",
      };
      this.fetchService.dictValue(data).then((res) => {
        console.log("this.fetchService.dictValue", res.data);
        if(res.code !== 0){
          return
        }
        if (res.code === 0 && res.data.length>0) {
          this.getKey = res.data[0].key;
          console.log('this.getDict',this.getKey);
        }else{
          this.getKey = '1'
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
@import "@/common/stylus/moon.scss";
.list-wenda .item {
  padding-bottom: 20px;
  margin-bottom: 0px;
}
.title-wrap {
  .title {
    font-size: 16PX;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
  }
}
.on-input {
  input {
    border-color: orange;
    background-color: rgba(orange, 0.3);
  }
}
.cube-radio-label,
.cube-checkbox-input {
  font-size: 16PX;
}
.input-row-wrap input,
.input-row-wrap textarea {
  font-size: 16PX;
}
.content-img {
  margin-top: 20px;
  width: 100%;
  /*height:calc(85vw * 9 / 16);*/
  overnflow: hidden;
  img {
    width: 100%;
    height: auto;
  }
}
.myProject-img {
  margin-top: 20px;
  width: 100%;
  height: 100%;
  overflow: hidden;
  img {
    width: 100%;
    height: auto;
  }
}
.organization-lists-title{
  text-align: justify;
  text-justify: distribute-all-lines;
}
.subject-title{
  text-align: justify;
  text-justify: distribute-all-lines;
}
.text-left{
  float: left;
}
.text-right{
  font-size: 17PX;
  text-align: left !important;
  font-family: dang,PingFang SC,miui,system-ui,-apple-system,BlinkMacSystemFont,Helvetica Neue,Helvetica,sans-serif;
}
</style>
